from pydantic import BaseModel, Field
from typing import Optional,Union,List
from enum import IntEnum, Enum

class APICode(IntEnum):
    Success = 0
    Failed = 1
    
class APIResult(BaseModel):
    code: APICode = Field(default=APICode.Success)
    msg: Optional[str] = Field(default="success")
    data: Optional[Union[dict,list]] = None

    def dict(self, *args, **kwargs):
        if kwargs and kwargs.get("exclude_none") is not None:
            kwargs["exclude_none"] = True
        return BaseModel.model_dump(self, *args, **kwargs)